import $http from '@/utils/http/index'
import { LoginReq, IRes, GetUserInfoReq, GetUserReq, AddUserReq, UpdateUserReq, GetRoleReq, DeleteUserInfoReq, GetUserMenuReq, GetUserRoleReq, DeleteRoleByUserIdReq, AddRoleByUserIdReq, AddRoleReq, EditeRoleReq, DeleteRoleReq, GetAuthByIdReq, DeleteAuthByIdReq, AddAuthByIdReq } from '../type/user';
import { AddFeedback, UpdateFeedback, GetFeedback, DeleteFeedback } from '../type/feedback'

/**
 * 登录
 * @param data 
 * @returns 
 */
export function login(data: LoginReq) {
  return $http.post<IRes>({
    url: "/api/user/login",
    data,
  });
}

/**
 * 获取用户数据
 * @param data 
 * @returns 
 */
export function getUser(data: GetUserReq) {
  return $http.get<IRes>({
    url: "/api/admin/getUserInfo",
    params: data,
  });
}

/**
 * 获取用户菜单
 * @param data 
 * @returns 
 */
export function getUserMenu(data: GetUserMenuReq) {
  return $http.get<IRes>({
    url: "/api/admin/getUserMenu",
    params: data,
  });
}

/**
 * 获取用户角色
 * @param data 
 * @returns 
 */
export function getRoleInfo(data: GetRoleReq) {
  return $http.get<IRes>({
    url: "/api/admin/getRoleInfo",
    params: data,
  });
}


/**
 * 获取用户角色
 * @param data 
 * @returns 
 */
export function getUserRole(data: GetUserRoleReq) {
  return $http.get<IRes>({
    url: "/api/admin/getUserRole",
    params: data,
  });
}


/**
 * 获取所有角色
 * @param data 
 * @returns 
 */
export function getAllRole() {
  return $http.get<IRes>({
    url: "/api/admin/getAllRole",
  });
}

/**
 * 根据角色id获取权限
 * @param data 
 * @returns 
 */
 export function getAuthByRoleId(data:GetAuthByIdReq) {
  return $http.get<IRes>({
    url: "/api/admin/getAuthByRoleId",
    params:data
  });
}



/**
 * 增加用户数据
 * @param data 
 * @returns 
 */
export function AddUser(data: AddUserReq) {
  return $http.post<IRes>({
    url: "/api/admin/addUserInfo",
    data,
  });
}

/**
 * 根据角色id增加权限
 * @param data 
 * @returns 
 */
 export function addAuthById(data: AddAuthByIdReq) {
  return $http.post<IRes>({
    url: "/api/admin/addAuthByRoleId",
    data,
  });
}

/**
 * 修改用户数据
 * @param data 
 * @returns 
 */
export function UpdateUser(data: UpdateUserReq) {
  return $http.patch<IRes>({
    url: "/api/admin/updateUserInfo",
    data,
  });
}


/**
 * 删除用户数据
 * @param data 
 * @returns 
 */
export function DeleteUser(data: DeleteUserInfoReq) {
  return $http.delete<IRes>({
    url: "/api/admin/deleteUserInfo",
    params: data,
  });
}

/**
 * 根据角色id删除权限
 * @param data 
 * @returns 
 */
 export function deleteAuthById(data: DeleteAuthByIdReq) {
  return $http.delete<IRes>({
    url: "/api/admin/deleteAuthByRoleId",
    params: data,
  });
}

/**
 * 删除角色
 * @param data 
 * @returns 
 */
export function deleteRoleById(data: DeleteRoleReq) {
  return $http.delete<IRes>({
    url: "/api/admin/deleteRoleById",
    params: data,
  });
}


/**
 * 根据用户id获取用户信息
 * @param data 
 * @returns 
 */
export function getUserInfo(data: GetUserInfoReq) {
  return $http.get<IRes>({
    url: "/api/user/getUserInfo",
    params: data
  });
}

/**
 * 获取所有用户
 * @returns 
 */
export function getAllUser() {
  return $http.get<IRes>({
    url: "/api/user/getAllUser"
  });
}


/**
 * 获取所有用户
 * @returns 
 */
 export function getAllAuth() {
  return $http.get<IRes>({
    url: "/api/admin/getAllAuth"
  });
}


/**
 * 获取反馈信息
 */
export function getFeedback(data: GetFeedback) {
  return $http.get<IRes>({
    url: '/api/user/getFeedback',
    params: data
  })
}


/**
 * 增加反馈信息
 */
export function addFeedback(data: AddFeedback) {
  return $http.post<IRes>({
    url: '/api/user/feedback',
    data
  })
}


/**
 * 增加用户角色
 */
export function addUserRole(data: AddRoleByUserIdReq) {
  return $http.post<IRes>({
    url: '/api/admin/addRolesByUserId',
    data
  })
}


/**
 * 更新反馈信息
 */
export function updateFeedback(data: UpdateFeedback) {
  return $http.patch<IRes>({
    url: '/api/user/updateFeedback',
    data
  })
}

/**
 * 删除反馈信息
 */
export function deleteFeedback(data: DeleteFeedback) {
  return $http.delete<IRes>({
    url: '/api/user/deleteFeedback',
    params: data
  })
}


/**
 * 删除用户全部角色
 */
export function deleteRole(data: DeleteRoleByUserIdReq) {
  return $http.delete<IRes>({
    url: '/api/admin/deleteRoleByUserId',
    params: data
  })
}

/**
 * 增加角色
 */
export function addRole(data: AddRoleReq) {
  return $http.post<IRes>({
    url: '/api/admin/addRole',
    data
  })
}

/**
 * 增加角色
 */
 export function editRole(data: EditeRoleReq) {
  return $http.patch<IRes>({
    url: '/api/admin/editRole',
    data
  })
}

